import React, { Component } from 'react'

export default class Demo extends Component {

    state = {
        count: 0
    }

    add = () => {
        // 获取原来的count值
        // const {count} = this.state
        // 更新状态
        // this.setState({count: count+1}, () => {
        //     console.log(this.state.count)
        // })
        // this.setState((state, props) => {
        //     return {count: state.count+props.a}
        // })
        // this.setState({count: this.state.count + 1})
        this.setState(state => ({count: state.count + 1}))
        this.setState(state => ({count: state.count + 1}))
        this.setState(state => ({count: state.count + 1}))
        this.setState(state => ({count: state.count + 1}))
    }

    render() {
        console.log('@@@');
        return (
            <div>
                <h1>当前求和为：{this.state.count}</h1>
                <button onClick={this.add}>加1</button>
            </div>
        )
    }
}